#include "concat.h"
#include <cstring>
using std::strlen;
using std::strcpy;
using std::strcmp;
Concat::Concat(const char*s):length((s!=0)?strlen(s+1):0)
{
	setConcat(s);
}
Concat::Concat(const Concat &copy):length(copy.length)
{
	setConcat(copy.sPtr);
}
Concat::~Concat()
{
	delete [] sPtr;
}
const Concat &Concat::operator +(const Concat &right)
{
	size_t newLength=(*this).length+right.length;
	char *temp=new char[newLength+1];
	strcpy(temp,(*this).sPtr);
	strcpy(temp+(*this).length,right.sPtr);
	delete [] sPtr;
	(*this).sPtr=temp;
	(*this).length=newLength;
	return *this;
}
const Concat &Concat::operator +(char right)
{
	(*this).sPtr[(*this).length+1]=right;
	(*this).length=(*this).length+1;
	return *this;
}
std::ostream &operator<<(std::ostream &out,const Concat &obj)
{
	out<<obj.sPtr;
	return out;
}
std::istream &operator >>(std::istream &inp,Concat &obj)
{
	char temp[100];
	inp>>temp;
	obj=temp;
	return inp;
}
const Concat &Concat::operator =(const Concat &right)
{
	if(&right!=this)
	{
		delete [] sPtr;
		(*this).length=right.length;
		setConcat(right.sPtr);
	}
	else
		std::cout<<"Nu poti asigna acelasi obiect\n";
	return *this;
}
void Concat::setConcat(const char *str2)
{
	(*this).sPtr=new char[(*this).length+1];
	if(str2!=0)
		strcpy((*this).sPtr,str2);
	else
		(*this).sPtr[0]='\0';
}
